import { Body, Controller, Post, Req } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AppCollectionService } from './collection.service';
// import { Collection } from './collection.entity';
// import { ApiRes, ApiResType } from 'src/common/decorator/api-res.decorator';
// import { AppCollectionListDto } from './dto/list.dto';
import { AddCollectionDto } from './dto/add.dto';
import { RemoveCollectionDto } from './dto/remove.dto';

@ApiTags('app合辑收藏模块')
@ApiBearerAuth()
@Controller('app/collection')
export class AppCollectionController {
  constructor(private readonly appCollectionService: AppCollectionService) {}

  // @ApiOperation({
  //   summary: '分页查询已收藏的单词列表',
  // })
  // @Post('/list')
  // @ApiRes(Collection, ApiResType.PAGE_ARRAY)
  // async list(@Body() data: AppCollectionListDto, @Req() request) {
  //   const { uid } = request.auth;
  //   return {
  //     data: await this.appCollectionService.findAll(uid, data),
  //   };
  // }

  @ApiOperation({
    summary: '收藏合辑',
  })
  @Post('/add')
  async add(@Body() collection: AddCollectionDto, @Req() request) {
    const { uid } = request.auth;
    const data = await this.appCollectionService.findOneByGatherId(
      collection.gatherId,
      uid,
    );
    if (data) {
      return {
        data: data,
      };
    }
    return {
      data: await this.appCollectionService.create(uid, collection),
    };
  }

  @ApiOperation({
    summary: '取消收藏',
  })
  @Post('/remove')
  async remove(@Body() data: RemoveCollectionDto, @Req() request) {
    const { uid } = request.auth;
    return {
      data: await this.appCollectionService.remove(data.gatherId, uid),
    };
  }
}
